package com.cloudfun.campusshare.device.protocol.decoder;

import com.cloudfun.campusshare.util.ByteUtil;

import java.util.function.BiConsumer;

/**
 * Created by Huqin on 2020/4/23
 */
public class PlainHexStringFieldDecoder<T> extends SingleValueFieldDecoder<T, String> {

    public PlainHexStringFieldDecoder(int start, int length, BiConsumer<T, String> fieldSetter) {
        super(start, length, fieldSetter);
    }

    @Override
    public void decode(byte[] data, T obj) {
        String hexString = ByteUtil.bytesToHexString(data);
        getFieldSetter().accept(obj, hexString);
    }
}
